class Node:
    def __init__(self, data):
        self.data = data
        self.next = None


class Linktable:
    def __init__(self):
        self.head = None
        self.size = 0

    def insert(self, data):
        """在链表头部插入新节点"""
        new_node = Node(data)
        new_node.next = self.head
        self.head = new_node
        self.size += 1
        return self  # 支持链式调用

    def delete(self):
        """删除并返回头节点数据"""
        if self.head is None:
            return None
        deleted_data = self.head.data
        self.head = self.head.next
        self.size -= 1
        return deleted_data

    def get_size(self):
        """获取当前链表长度"""
        return self.size

    def __repr__(self):
        """可视化链表结构"""
        nodes = []
        current = self.head
        while current:
            nodes.append(str(current.data))
            current = current.next
        return "->".join(nodes) if nodes else "Empty Linktable"


if __name__ == "__main__":
    # 创建链表实例
    my_list = Linktable()

    # 插入测试数据
    my_list.insert(1).insert(2).insert(3)

    print(f"链表结构：{my_list}")
    print("链表长度：", my_list.get_size())  # 输出：3

    # 删除操作
    deleted = my_list.delete()
    print("删除的元素：", deleted)  # 输出：3
    print("删除后结构：", my_list)  # 输出：2->1
    print("删除后长度：", my_list.get_size())  # 输出：2